﻿namespace ElisVK.Data.AudioSources
{
    using System.Text;
    using Utils;

    public class VKBookmarksAudioSource : AudioSource
    {
        private string _uids;

        public VKBookmarksAudioSource()
            : base("VK Bookmarks", true)
        {
        }

        public VKBookmarksAudioSource(string uids)
            : base("VK Bookmarks", true)
        {
            _uids = uids;
        }

        protected override void LoadChildren()
        {
            if (string.IsNullOrEmpty(_uids))
                return;

            var buff = VKHelper.DownloadData(
                string.Format("https://api.vkontakte.ru/method/users.get.xml?uids={0}&fields=uid,first_name,last_name&access_token={1}", _uids, App.SessionInfo.AccessToken));

            var friendsList = UserInfo.ParseUserInfosFromXML(Encoding.UTF8.GetString(buff));

            friendsList.Sort();

            foreach (var friend in friendsList)
            {
                Children.Add(new VKFriendAudioSource(friend));
            }
        }
    }
}
